<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="王雨峰, 博客" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="##干了三件事

在Mac上安装Hexo
将博客同时部署到Github Page和Gitcafe Page
将域名分别绑定到了两个网站(海内、海外)

##在Mac上安装Hexo安装很容易，就和在Win上差不多。npm源是不是被半墙了？下载速度很慢，现在这网络环境，唉。
用Hexo进行各项操作时，命令基本都得加sudo，如果不加就会出错。
在用Git推送时，总是提示我SSH有错。反复查询后发现，不">
<meta property="og:type" content="article">
<meta property="og:title" content="将博客同步发布到天朝和美帝">
<meta property="og:url" content="http://wangyufeng.org/2015/08/23/chong-xin-bu-shu-hexo/index.html">
<meta property="og:site_name" content="王雨峰的博客">
<meta property="og:description" content="##干了三件事

在Mac上安装Hexo
将博客同时部署到Github Page和Gitcafe Page
将域名分别绑定到了两个网站(海内、海外)

##在Mac上安装Hexo安装很容易，就和在Win上差不多。npm源是不是被半墙了？下载速度很慢，现在这网络环境，唉。
用Hexo进行各项操作时，命令基本都得加sudo，如果不加就会出错。
在用Git推送时，总是提示我SSH有错。反复查询后发现，不">
<meta property="og:image" content="http://7xku3h.com1.z0.glb.clouddn.com/15-8-23/73049177.jpg">
<meta property="og:image" content="http://7xku3h.com1.z0.glb.clouddn.com/15-8-23/90310523.jpg">
<meta property="og:updated_time" content="2015-08-23T13:44:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="将博客同步发布到天朝和美帝">
<meta name="twitter:description" content="##干了三件事

在Mac上安装Hexo
将博客同时部署到Github Page和Gitcafe Page
将域名分别绑定到了两个网站(海内、海外)

##在Mac上安装Hexo安装很容易，就和在Win上差不多。npm源是不是被半墙了？下载速度很慢，现在这网络环境，唉。
用Hexo进行各项操作时，命令基本都得加sudo，如果不加就会出错。
在用Git推送时，总是提示我SSH有错。反复查询后发现，不">
<meta name="twitter:image" content="http://7xku3h.com1.z0.glb.clouddn.com/15-8-23/73049177.jpg">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://wangyufeng.org/2015/08/23/chong-xin-bu-shu-hexo/"/>

  <title> 将博客同步发布到天朝和美帝 | 王雨峰的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">王雨峰的博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">随便写点东西，为互联网贡献一些比特~</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                将博客同步发布到天朝和美帝
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-08-23T18:20:02+08:00" content="2015-08-23">
              2015-08-23
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>##干了三件事</p>
<ul>
<li>在Mac上安装Hexo</li>
<li>将博客同时部署到Github Page和Gitcafe Page</li>
<li>将域名分别绑定到了两个网站(海内、海外)</li>
</ul>
<p>##在Mac上安装Hexo<br>安装很容易，就和在Win上差不多。npm源是不是被半墙了？下载速度很慢，现在这网络环境，唉。</p>
<p>用Hexo进行各项操作时，命令基本都得加sudo，如果不加就会出错。</p>
<p>在用Git推送时，总是提示我SSH有错。反复查询后发现，不仅得把SSH公钥传到Github上，<strong>还得把SSH私钥加入到本机SSH客户端。</strong>但在Win上使用Git却没有这一步，可能是自动添加了吧，毕竟用的是msysgit集成环境。</p>
<p>##同时部署到两个网站<br>毕竟Github在美帝的地盘上，我们访问起来速度不好，曾经还一度被墙过。且听说百度对Github Pages的收录不好。所以打算同步在Github和Gitcafe上更新博客，毕竟他们都提供Page服务。毕竟Gitcafe在国内，既然已经备案了，那一定会遵纪守法嘛。</p>
<p>操作做法：打开Hexo根目录下的 <code>_config.yml</code> ,如下填写：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">deploy:</div><div class="line">  type: git</div><div class="line">  message: &quot;&quot;</div><div class="line">  repo:</div><div class="line">    github: git@github.com:wangyufeng0615/wangyufeng0615.github.io.git</div><div class="line">    gitcafe: git@gitcafe.com:azzwacb9001/azzwacb9001.git,gitcafe-pages</div></pre></td></tr></table></figure></p>
<p>注意，我在github那一行后面没写分支，默认是master。</p>
<p>现在再使用<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo d</div></pre></td></tr></table></figure></p>
<p>就可以同时推送博客到两个网站上了。如果是mac的话，不加配置的话，别忘了加<code>sudo</code></p>
<hr>
<p>不过刚才做了下ping测试，Gitcafe也不是很快。印象中以前都40多ms。<br><img src="http://7xku3h.com1.z0.glb.clouddn.com/15-8-23/73049177.jpg" alt=""><br>上为Gitcafe,下为Github</p>
<p>我觉得我进行了一次响亮的自行打脸。</p>
<p>##令同一个域名分流海内外流量<br>我想让<code>wangyufeng.org</code>这个域名，想让国内的流量访问到Gitcafe，海外的流量访问到Github，怎么做呢？</p>
<p>其实很容易，在DNS设置里如图：<br><img src="http://7xku3h.com1.z0.glb.clouddn.com/15-8-23/90310523.jpg" alt=""><br><strong>主机记录那里我改成了www，这样的话访问<code>wangyufeng.org</code>就可以自动被解析为<code>www.wangyufeng.org</code>，否则必需输入www。</strong></p>
<p>另外，无论是Github还是Gitcafe，都推荐使用<code>CNAME</code>记录。Gitcafe甚至必需使用CNAME，它说</p>
<blockquote>
<p>如果您的域名注册商管理界面不支持 CNAME 记录添加，可以使用 DNSPod 或 CloudFlare 等支持 CNAME 记录的第三方域名解析服务来管理您的域名。</p>
</blockquote>
<p>为什么呢？Github官网如是说：</p>
<blockquote>
<p>We strongly recommend that you use a custom subdomain for these reasons:</p>
<ul>
<li>It gives your GitHub Pages site the benefit of our Content Delivery Network.</li>
<li>It will not be affected by changes in the underlying IP addresses of GitHub’s servers.</li>
<li>Pages will load significantly faster because Denial of Service protection can be implemented more efficiently.</li>
</ul>
</blockquote>
<p>大意是</p>
<ul>
<li>有CDN给你加速</li>
<li>就算我们挪窝了你页面也能用</li>
<li>更好的DOS保护</li>
</ul>
<p>所以，如果不是弄这种流量的分流，正常情况下一条CNAME解析就足够了。<br>现在网上的绝大多数教程/帖子都是A记录，还有A记录和CNAME记录混用的。</p>
<p>这件事儿带给我的收获是，多看看官网的东西肯定没错。看网上的经验贴前也得注意发帖日子。</p>
<p>毕竟不是所有的东西都像C语言那样，(近似于)静静地待在角落里一动不动，一声不吭。</p>
<hr>
<p>如果大家对Hexo建博客感兴趣，不妨搜索一下<code>Github Hexo 博客</code>这样的关键字，教程非常多。很好玩。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/08/20/ping-guo-de-yue-liang-bi-jiao-yuan/" rel="next" title="苹果的月亮比较圆">
                <i class="fa fa-chevron-left"></i> 苹果的月亮比较圆
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/08/25/yu-yan-shi-fen-bu-shi-xi-tong/" rel="prev" title="语言是分布式系统吗？">
                语言是分布式系统吗？ <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Alan" />
          <p class="site-author-name" itemprop="name">Alan</p>
          <p class="site-description motion-element" itemprop="description">Alan Wang's personal blog.</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">57</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <p class="post-toc-empty">此文章未包含目录</p>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Alan</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a> 
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
